<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>用户注册</title>
	<jsp:include page="../../../main/mp/resource.jsp"	/>
</head>
<body>

<div class="mui-content">
	<h4 style="margin:20px auto;text-align:center">用户注册</h4>
	<form id="form-common" class="mui-input-group" action="register/create">
		<input type="hidden" name="openId" id="openId" value="${openId}" />
		<div class="mui-input-row">
			<label>姓名</label>
			<input type="text"  name="name" id="name" class="mui-input-clear" placeholder="请输入姓名">
		</div>
		<div class="mui-input-row">
			<label>登录账号</label>
			<input type="text" name="username" id="username" class="mui-input-clear" placeholder="请输入登录账号">
		</div>
		<div class="mui-input-row">
			<label>登录密码</label>
			<input  type="password" name="password" id="password" class="mui-input-password" placeholder="请输入登录密码">
		</div>
		<div class="mui-input-row">
			<label>密码确认</label>
			<input type="password" name="passwordConfirm" id="passwordConfirm" class="mui-input-password" placeholder="请输入登录密码">
		</div>
		<div class="mui-button-row">
			<button type="button" class="mui-btn mui-btn-primary" id="btn-save-common">提交</button>
		</div>
	</form>

</div>

</body>

<script>

    $(function(){
        $("#btn-save-common").click(function(e){
            if(!checkData()){
                return false;
			}
            __ajax_post("<%=path%>/mp/user/validate/account",{"username":$('#username').val()},function(data){
              	if(data == true){
                    $("#btn-save-common").hide();
                    __ajax_post($("form#form-common").attr("action"),$("form#form-common").serialize(),function(data){
                        if(data.state == 1){
                            var datas={"username":$("#username").val(),"password":$("#password").val(),"openId":$("#openId").val()};
                            __ajax_post("<%=path%>/mp/register/connectMp",datas,function(data){
                                console.log(data);
                                if(data.state == "1"){
                                    mui.alert('注册成功', '提示', function() {
                                        location.replace("<%=path%>/mp/index");
                                    });
								}else{
                                    mui.alert(data.message, '提示', function() {
                                        location.replace("<%=path%>/mp/login");
                                    });
								}
                            });
                        }else{
                            mui.alert('注册失败', '提示', function() {
                                location.replace("<%=path%>/mp/login");
                            });
                        }
                    });
				}else{
                    mui.alert('请输入有效的手机号/邮箱账号, 或已被使用', '提示');
				}
            });
        });
    });

    function checkData(){
        if($('#name').val() == ""){
            mui.alert('名称不能为空', '提示');
            return false;
		}
        if($('#username').val() == ""){
            mui.alert('登录账号不能为空', '提示');
            return false;
        }
        if($('#password').val() == ""){
            mui.alert('密码不能为空', '提示');
            return false;
        }
        if($('#passwordConfirm').val() != $('#password').val()){
            mui.alert('确认密码和登录密码不一致', '提示');
            return false;
        }
		return true;
	}
</script>

</html>